// $codepro.audit.disable packagePrefixNamingConvention
/**
 * package for all the model classes to fit the mvc format
 */
package javamonsters.model;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.math.BigDecimal;

/**
 * Character class holds details about each character within the game,
 * including name, profession points, and its ship
 * @author elahurd3
 * @version 1.0
 */
public class Character implements java.io.Serializable  {

	/**
	 * 
	 */
	private static final long serialVersionUID = 910354884610877206L;
	
	/**
	 * the character's name and the difficulty of the game
	 */
	private final String name, difficulty; //difficulty needs to be placed in its correct class
	
	/**
	 * the points for each of the respective skills 
	 */
	private int traderPts, pilotPts, engineerPts, fighterPts;
	
	/**
	 * the monetary unit
	 */
	private BigDecimal credits;
	
	/**
	 * a ship object
	 */
	private Ship ship;

	/**
	 * @param name name of the character
	 * @param fighterPts points in the fighter skill
	 * @param engineerPts points in the engineer skill
	 * @param pilotPts points in the pilot skill
	 * @param traderPts points in the trader skill
	 * @param credits monetary unit
	 * @param ship ship object
	 * @param difficulty difficulty of the game
	 */
	public Character(String name, int fighterPts, int engineerPts, int pilotPts,  // $codepro.audit.disable largeNumberOfParameters
	       int traderPts, BigDecimal credits, Ship ship, String difficulty) {
		
		this.name = name;
		this.traderPts = traderPts;
		this.pilotPts = pilotPts;
		this.engineerPts = engineerPts;
		this.fighterPts = fighterPts;
		this.credits = credits;
		this.ship = ship;
		this.difficulty = difficulty;
	}
	
	/**
	 * Remove credits from the Character
	 * @param amount number of credits to remove
	 */
	public void removeCredits(BigDecimal amount) {
		this.credits = this.credits.subtract(amount);
	}
	
	/**
	 * Add credits to the Character
	 * @param amount number of credits to add
	 */
	public void addCredits(BigDecimal amount) {
		this.credits = this.credits.add(amount);
	}
	
	/**
	 * Prints the character's details in a string statement
	 * @return a string containing the character's name, 
	 * profession skills, difficulty, and ship type 
	 */
	public String toString() {
		return "Name: " + getName() + ", Fighter: " + getFighterPts() +
				", Engineer: " + getEngineerPts() + 
				", Pilot: " + getPilotPts() + ", Trader: " + 
				getTraderPts() + ", Credits: " + getCredits() +
				", Ship Type: " + getShip().getShipType() +
				", Difficulty: " + difficulty;
	}
	
	/**
	 * Sets the Ship type
	 * @param ship the new Ship type for the player's Ship
	 */
	public void setShip(Ship ship) {
		this.ship = ship;
	}
	
	/**
	 * Sets the credit amount
	 * @param credits the new credit amount for the player's credits
	 */
	public void setCredits(BigDecimal credits) {
		this.credits = credits;
	}
	
	/**
	 * Sets the trader points
	 * @param traderPts the new trader skill points for the player
	 */
	public void setTraderPts(int traderPts) {
		this.traderPts = traderPts;
	}
	
	/**
	 * Sets the pilot points
	 * @param pilotPts the new trader skill points for the player
	 */
	public void setPilotPts(int pilotPts) {
		this.pilotPts = pilotPts;
	}
	
	/**
	 * Sets the pilot skill points
	 * @param engineerPts the new engineer skill points for the player
	 */
	public void setEngineerPts(int engineerPts) {
		this.engineerPts = engineerPts;
	}
	
	/**
	 * Sets the fighter skill points
	 * @param fighterPts the new fighter skill points for the player
	 */
	public void setFighterPts(int fighterPts) {
		this.fighterPts = fighterPts;
	}
	
	/**
	 * Getter for name
	 * @return a String of the character's name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Getter for ship
	 * @return a Ship type of the character
	 */
	public Ship getShip() {
		return ship;
	}
	
	/**
	 * Getter for trader points
	 * @return an int representing the character's trader skill points
	 */
	public int getTraderPts() {
		return traderPts;
	}
	
	/**
	 * Getter for pilot points
	 * @return an int representing the character's pilot skill points
	 */
	public int getPilotPts() {
		return pilotPts;
	}
	
	/**
	 * Getter for engineer points
	 * @return an int representing the character's engineer skill points
	 */
	public int getEngineerPts() {
		return engineerPts;
	}
	
	/**
	 * Getter for fighter points
	 * @return an int representing the character's fighter skill points
	 */
	public int getFighterPts() {
		return fighterPts;
	}
	
	/**
	 * Getter for credits
	 * @return an int representing the character's credit amount
	 */
	public BigDecimal getCredits() {
		return credits;
	}
	
	/**
	 * writes object to a save file
	 * 
	 * @param filename file to be saved to
	 * @throws IOException
	 */
	public void writeObject(String filename) {
		try {
			final ObjectOutputStream out = new ObjectOutputStream(
					new FileOutputStream(filename + ".dat"));
			try {
				out.writeObject(this); 
			} finally {
				out.close();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
